<template>
  <router-link :to="`/video/${video.id}`" class="video-list-item">
    <div class="item-left">
      <div class="video-thumbnail">
        <img 
          :src="video.cover_url || '/default-cover.svg'" 
          :alt="video.title" 
          class="thumbnail-img"
          @error="handleImageError"
        />
        <span class="video-duration">{{ video.duration }}</span>
      </div>
    </div>
    <div class="item-right">
      <h4 class="video-title">{{ video.title }}</h4>
      <div class="video-stats">
        <span class="view-count">{{ formatCount(video.view_count) }}播放</span>
        <span class="danmaku-count">{{ formatCount(video.danmaku_count) }}弹幕</span>
      </div>
      <div class="video-uploader">
        {{ video.nickname || video.username }}
      </div>
    </div>
  </router-link>
</template>

<script>
export default {
  name: 'VideoListItem',
  props: {
    video: {
      type: Object,
      required: true
    }
  },
  setup(props) {
    // 格式化数量（如1000 -> 1万）
    const formatCount = (count) => {
      if (count >= 10000) {
        return (count / 10000).toFixed(1) + '万';
      }
      return count.toString();
    };

    // 处理封面图片加载失败
    const handleImageError = (event) => {
      event.target.src = '/default-cover.svg';
    };

    return {
      formatCount,
      handleImageError
    };
  }
};
</script>

<style scoped>
.video-list-item {
  display: flex;
  text-decoration: none;
  color: #333;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.2s;
}

.video-list-item:hover {
  background-color: #f5f5f5;
}

.video-list-item:last-child {
  border-bottom: none;
}

.item-left {
  flex-shrink: 0;
  margin-right: 12px;
  width: 100px;
  height: 70px;
}

.video-thumbnail {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  background-color: #f0f0f0;
}

.thumbnail-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-duration {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 1px 4px;
  font-size: 11px;
  border-radius: 2px;
}

.item-right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.video-title {
  margin: 0 0 6px 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-stats {
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
}

.video-uploader {
  font-size: 12px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 响应式调整 */
@media (max-width: 1024px) {
  .item-left {
    width: 80px;
    height: 60px;
  }
  
  .video-title {
    font-size: 13px;
  }
  
  .video-stats,
  .video-uploader {
    font-size: 11px;
  }
}
</style>